﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ChangeHope.Common
{
    public class Util
    {
        /// <summary>
        /// 将一个数组组和一个列名称组装成where中的in条件
        /// 一般用于根据主键进行查询
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        public static string GetWhereInClause(List<int> ids, string columns,string condition="and")
        {
            string strWhere = " "+condition+" "+columns+" in ( ";
            bool hasStore = false;
            for (int i = 0; i < ids.Count; i++)
            {
                hasStore = true;
                strWhere += ids[i].ToString() + ",";
            }
            if (!hasStore)
                strWhere += "0,";
            strWhere = strWhere.Substring(0, strWhere.Length - 1);
            strWhere += ") ";
            return strWhere;
        }
    }
}
